<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>请假系统-登录界面</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet">

    <link th:href="@{/css/animate.css}" rel="stylesheet">
    <link th:href="@{/css/style.css}" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>if(window.top !== window.self){ window.top.location = window.location;}</script>

</head>
<!-- 算术验证码 -->
<script type='text/javascript'>
    var code ; //在全局定义验证码
    function createCode(){
        code = "";
        var checkCode = document.getElementById("code");
        var index1 =  Math.floor(Math.random()*10);//取得随机数（0~9）
        var index3 = Math.floor(Math.random()*10);//取得随机数（0~9）
        var timestamp = (new Date()).valueOf();// 获取当前时间戳
        var staps = parseInt(timestamp%10);// 求余得到个位数，进行伪随机事件

        // 进行验证码拼接
        code +=index1;
        // 伪随机算法
        if(staps == 1 | staps == 4 |staps == 7 |staps == 0){
            code += "+";
        }else if(staps == 2 | staps == 5 |staps == 8) {
            code += "-";
        }else if(staps == 3 | staps == 6 |staps == 9) {
            code += "×";
        }
        code +=index3 + "=";

        checkCode.value = code; // 把code值赋给验证码
    }
    //校验验证码
    function validate(message){
        var number;
        var inputCode = document.getElementById("input").value;
        if(inputCode != null && inputCode != ""){
            var split1 = code.split("=")[0];
            if(split1.split("+")[1] != "" && split1.split("+")[1] != null){
                number = parseInt(split1.split("+")[0]) + parseInt(split1.split("+")[1]);
            }
            if(split1.split("-")[1] != "" && split1.split("-")[1] != null){
                number = parseInt(split1.split("-")[0]) - parseInt(split1.split("-")[1]);
            }
            if(split1.split("×")[1] != "" && split1.split("×")[1] != null){
                number = parseInt(split1.split("×")[0]) * parseInt(split1.split("×")[1]);
            }
            if(number != inputCode ) {
                Message('error', '验证码错误!', 2000);
                createCode();//刷新验证码
                document.getElementById("input").value = "";//清空文本框
                return false;
            }
            return true;
        }else {
            Message('warning', '请输入验证码', 2000);
            return false;
        }
    }
</script>
<script type="text/javascript">
    window.onload=function(){
        createCode();
    }
</script>
<style type='text/css'>
    #code{
        font-family:Arial,宋体;
        font-style:italic;
        color:green;
        border:0;
        padding:2px 3px;
        letter-spacing:3px;
        font-weight:bolder;
    }
</style>
<body class="gray-bg">

    <div class="middle-box text-center loginscreen  animated fadeInDown">
        <div>
            <div>

                <h1 class="logo-name">
                    <img style="border-radius:100em;margin-bottom:50px;width:200px;height:200px;text-align:center;"
                         th:src="@{/img/profile_small.jpg}"
                ></h1>

            </div>
            <h3 th:text="#{login.welcome}">请假系统</h3>

            <form class="m-t" role="form" th:action="@{/login.action}" method="post" onsubmit="return validate()">
                <div class="form-group">
                    <input type="text" name="userId" value="123" class="form-control" th:placeholder="#{login.username}" required=""
                           onkeyup="value=value.replace(/[^0-9]/g,'')" onpaste="value=value.replace(/[^0-9]/g,'')" oncontextmenu = "value=value.replace(/[^0-9]/g,'')">
                </div>
                <div class="form-group">
                    <input type="password" name="password" value="123" class="form-control fa fa-eye-slash"
                           th:placeholder="#{login.password}" required="">
                </div>
                <div class="input-group m-t m-b">
                    <input type="text" class="form-control" id="input"
                           placeholder="填写右侧的验证码" value="" maxlength="4"
                           data-validate="required:请填写验证码" />
                    <span class="input-group-addon no-padding">
                        <input class="passcode col-sm-4"
                               style="height:34px;cursor:pointer;width:80px"
                               type="button" id="code" onclick="createCode()"
                               value="点击刷新"/>
                    </span>
                </div>

                <button type="submit" class="btn btn-primary block full-width m-b" th:text="#{login.button}">登 录</button>

            </form>
            <a class="center" th:href="@{/toLoginPage(l='zh_CN')}">中文</a> | <a th:href="@{/toLoginPage(l='en_US')}">English</a>
        </div>
    </div>

    <!-- 全局js -->
    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>

    <!-- Message: alert整合包 -->
    <script th:src="@{/js/bootstrapMessage.js}"></script>

</body>

</html>
